#!/usr/bin/python3
fname = '/usr/share/plasma/plasmoids/org.kde.desktopcontainment/contents/config/main.xml'
previewPluginText = "ffmpegthumbs,opendocumentthumbnail,kraorathumbnail,audiothumbnail," \
                    "imagethumbnail,exrthumbnail,jpegthumbnail,windowsimagethumbnail," \
                    "svgthumbnail,comicbookthumbnail,directorythumbnail,textthumbnail," \
                    "blenderthumbnail,djvuthumbnail,gsthumbnail,cursorthumbnail," \
                    "fontthumbnail,rawthumbnail,ebookthumbnail"
inp = open(fname, 'r')
output = []
previewPluginsFlag = False
arrangementFlag = False
for line in inp:
    if '<entry name="previewPlugins"' in line:
        previewPluginsFlag = True
    if '<entry name="arrangement"' in line:
        arrangementFlag = True
    if '</entry>' in line:
        previewPluginsFlag = False
        arrangementFlag = False
    if previewPluginsFlag and '<default>' in line:
        output.append(f'      <default>{previewPluginText}</default>\n')
    elif arrangementFlag and '<default>' in line:
        output.append('      <default>1</default>\n')
    else:
        output.append(line)
inp.close()
out = open(fname, 'w')
print(*output, sep='', file=out)
out.close()
